
export function formatDate(fmt, date) {
        let ret;
        const opt = {
            "y+": date.getFullYear().toString(),        // 年
            "M+": (date.getMonth() + 1).toString(),     // 月
            "d+": date.getDate().toString(),            // 日
            "h+": date.getHours().toString(),           // 时
            "m+": date.getMinutes().toString(),         // 分
            "s+": date.getSeconds().toString()          // 秒
            // 有其他格式化字符需求可以继续添加，必须转化成字符串
        };
        for (let k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
            }
        }
        return fmt;

}


export class MyDate {
    oldDate;
    day;
    hour;
    mill;
    sec;


    constructor(oldDate) {
        this.oldDate=oldDate
        this.getSubDays(oldDate)
        this.getSubHour(oldDate)
        this.getSubMill(oldDate)
        this.getSubSec(oldDate)
    }


    getSubDays(oldDate) {

       this.day= Math.floor((new Date().getTime()-oldDate.getTime())/60/60/24/1000)
        return this.day
    }

    getSubHour(oldDate){
        this.hour= Math.floor((new Date().getTime()-oldDate.getTime())/60/60/1000-this.day*24)

        return this.hour
    }

    getSubMill(oldDate){

        this.mill= Math.floor((new Date().getTime()-oldDate.getTime())/60/1000-(this.hour*60+this.day*24*60))
        return this.mill
    }

    getSubSec(oldDate){
        this.sec=Math.floor((new Date().getTime()-oldDate.getTime())/1000-(this.hour*60*60+this.day*24*60*60+this.mill*60))
        return this.sec
    }



}